package com.syxp.pda.dao.base.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.syxp.pda.core.dao.impl.BaseDaoImpl;
import com.syxp.pda.dao.base.UserDao;
import com.syxp.pda.entity.base.User;

public class UserDaoImpl extends BaseDaoImpl<User> implements UserDao{

	public UserDaoImpl(){
		super(User.class) ;
	}

	@Override
	public User queryUserByAccount(final String account) {
		List<User> list = (List<User>)getHibernateTemplate().execute(new HibernateCallback(){

			@Override
			public Object doInHibernate(Session arg0)
					throws HibernateException, SQLException {
				Query query = getSession().createQuery("from User where userAccount='"+account+"'");
				return query.list();
			}
		});
		if(list.size()>0) {
			return list.get(0);
		} else {
			return null;
		}
	}
}
